package com.leetcode.题库;

import com.leetcode.common.model.ListNode;

/**
 * @author 覃国强
 * @date 2022-03-24 16:49
 */
public class 题库_0021_合并两个有序链表 {


  static
  class Solution {
    public ListNode mergeTwoLists(ListNode list1, ListNode list2) {
      ListNode head = new ListNode();
      ListNode node = head;
      while (list1 != null && list2 != null) {
        if (list1.val < list2.val) {
          node.next = list1;
          list1 = list1.next;
        } else {
          node.next = list2;
          list2 = list2.next;
        }

        node = node.next;
      }
      node.next = list1 != null ? list1 : list2;

      return head.next;
    }
  }

}
